In this video you will learn one of the most frequently used applications for moving averages and the
finance and investment industry for decades.
Financial traders and in particular traders who rely on technical analysis rather than fundamental analysis
rely on so-called momentum strategies with a simple moving averages and you will see in a minute.
The intuition behind the strategy.
But first of all we still have imparted the S&P 500 closed data.
So let's have a look at the first five data points and the last five data points and let's create a
brand new column called A simple moving average is 50 with um the simple moving average of the close
price with a window of 50.
So we're using the other rolling method on the S&P 500 data frame with a window of 50.
And we also need 50 periods to calculate the simple moving average and we change the mean method because
we want to calculate moving averages.
So let's do this here and let's have a look here at our data frame and we can see here that we have
successfully added the column simple moving averages.
50 and it's actually no surprise that for the first forty nine timestamps we have here any anywhere
use because for these times stands we do not have 50 data points.
So we have only nominal values in those columns starting from the 15th.
The time stamp until the very last time stamp here.
So here we can see the very last day of 2018.
So here we have the price for the S&P 500 and this is actually the simple moving average for the last
the preceding 50 days and now we can also plot the S&P 500 data frame with our two columns.
So the actual close price and uh the simply moving average is 50.
And of course you can do this here with the plot method so let's have a look here so we can see here
in blue are the close price and in green.
The simple moving average is 50.
And we can see here that uh with uh moving averages the kind of smoothing.
Yeah.
Our data.
So here at each and every timestamp we have actually the average for the preceding 50 timestamps.
So therefore we have kind of a smooth and curve.
So now let's move on and also create a column for the simple moving average 200.
So here we have a rolling window of 200 timestamps and again we can do this year with the rolling method
and past 200 to the windows perimeter and we want to calculate the simple moving average with the mean
method so let's have a look here.
Here we have the last five timestamps or for the simple moving average is two hundredths or the first
one hundred ninety nine timestamps in our data frame that we have actually and a values party and the
very end.
Of course we have values.
For the simple moving average 50 and 200.
And let's also call you at the info method.
And we can see here that in the close column we have two thousand five hundred sixty nine values and
consequently for the SMI 50 year we have forty nine fewer data points and for the estimated two hundred
we have one hundred and ninety nine fewer data points.
And now let's also plot all the three columns here.
So let's do this.
So here we have uh the close column the S M A 50 and the ESA 200 column.
And we can also see here that the S M A 50 is that's forty nine timestamps later and the S and may one
hundred ninety nine timestamps later.
And now let's only plot the estimate curve.
So we're actually only plotting the last two columns here.
So here we f and blue are the simple moving average is 50 and green.
The simple moving average is 200 and it's no surprise that the estimate 200 is even more smooth than
the SMI 50 and we could also say that the shorter term estimate.
So the S and may 50 is actually reacting faster to price changes than the estimated 200.
So for example here the blue line starts to decrease sharply and actually the Green Line takes some
more time to actually also decrease.
And this is actually the basis for a very simple trading strategy.
So we have two simple moving averages with different windows.
So we have one longer term window so you two hundred and one shorter term window 50.
And the idea is that actually the trader invests when the shorter term S.M. A is above the longer term
as an A and you should divest or even go short when the opposite holds true.
So in this example here whenever the blue line is above uh the green line then we should invest into
the S&P 500.
So it's here for example or here or in this period and whenever the blue line is uh below the green
line.
So for example here or here or here then we should divest from the S&P 500 or even go short.
And the rationale behind this is that the shorter assume a captures the most recent trends or the momentum
and that the most recent trend will persist also in the near future.
So for example let's have a look here.
So here initially our blue line.
So the s may 50 is below the green line and in this case we are not invested in the S&P 500 or even
we are short the S&P 500.
But then the S&P 500 starts to increase and also the asset may 50 increase US uh faster than the S&P
200.
So the most recent trend or the most recent momentum is positive.
And therefore when both lines are crossing here and the blue line goes above the green line then we
should invest in the S&P 500.
And this is in this case here for a very long time period.
So we should invest here in the year 2012 and then we should divest into a 16 and then for a short term
period.
We are not investors.
And then from to 16 to to 18 or to 19 we sought to again be invested in the S&P 500.
So this is the rationale behind this trading strategy and this is actually based on simple moving averages
and the opposite of a momentum strategy would be a contrarian strategy.
So we are finished with this video and I hope to see you also in the next one by.